import req from '@/utils/request';
import * as URL from '@/constants/api';

// 登陆
export function login(params: any) {
  return req({
    url: URL.LOGIN,
    method: 'post',
    data: params,
    headers: { 'content-type': 'application/x-www-form-urlencoded' },
  })
    .then((res) => {
      // 记token
      localStorage.setItem('TOKEN', `Bear ${res.data.token}`);
      // 记username
      localStorage.setItem('username', `${res.data.data.username}`);
      return res.data;
    })
    .catch((err) => Promise.reject(err.response.data));
}

// 用户项目列表
export function getprojectList(id: any) {
  return req({
    url: `${URL.PROJECT_LIST}/${id}`,
  })
    .then((res) => res);
}
